package com.wowangz.cms.dailyoperation.storechannel.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wowangz.cms.common.utils.SysConstant;
import com.wowangz.cms.dailyoperation.storechannel.pojo.StoreChannel;
import com.wowangz.cms.syscore.exception.ServiceException;
import com.wowangz.cms.syscore.service.BaseService;

public class StoreChannelService extends BaseService {

	private Logger logger = LoggerFactory.getLogger(StoreChannelService.class);
	
	/**
	 * 分页查询总条数
	 * 
	 * @param map
	 * @return
	 */
	public long findResultCount(HashMap<String, Object> map) throws ServiceException {
		Long countNum = this.getSqlSession().selectOne("StoreChannel.queryChannelCount", map);
		return countNum;
	}

	/**
	 * 查询记录集合
	 * 
	 * @param map
	 * @return
	 */
	public List<StoreChannel> findResultList(HashMap<String, Object> map) throws ServiceException {
		List<StoreChannel> list = this.getSqlSession().selectList("StoreChannel.queryChannelPage", map);
		return list;
	}
	
	/**
	 * 验证信息
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public boolean validationChannel(HashMap<String, Object> map) throws ServiceException {
		Long countNum = this.getSqlSession().selectOne("StoreChannel.validationChannel", map);
		if(countNum != 0){
			return false;
		}else{
			return true;
		}
	}
	
	/**
	 * 新增商户通道
	 *
	 */
	public void addChannel(StoreChannel storeChannel) throws ServiceException {
		this.getSqlSession().insert("StoreChannel.insertChannel", storeChannel);
	}
	
	/**
	 * 根据ID查询商户
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public StoreChannel findChannelById(String id) throws ServiceException {
		StoreChannel storeChannel = this.getSqlSession().selectOne("StoreChannel.findChannelById", id);
		return storeChannel;
	}
	/**
	 * 修改商户信息
	 *
	 */
	public void updateChannel(StoreChannel storeChannel) throws ServiceException {
		this.getSqlSession().update("StoreChannel.updateChannel", storeChannel);
	}
	
	/**
	 * 根据商户ID查询通道
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public StoreChannel findChannelByStoreId(String id) throws ServiceException {
		Map map = new HashMap();
		map.put("storeid", id);
		map.put("statusid", SysConstant.RecordStatus.VALID);
		List list = this.getSqlSession().selectList("StoreChannel.findChannelByStoreId", map);
		StoreChannel channel = null;
		if(list != null && list.size() > 0)
		{
			channel = (StoreChannel)list.get(0);
		}
		return channel;
	}
}
